package com.cn.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import com.cn.entity.Zhenduan;



public class ZhenduanDao {
	

	private static SessionFactory sessionFactory;
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	Session session;

	
	
	public List<Zhenduan> scanAll(){
		session=sessionFactory.openSession();
		String hql="from Zhenduan";
		Query query=session.createQuery(hql);
		List<Zhenduan> list=query.list();
	   
	     return list;
		
		
	}
	public Zhenduan scanOne(int zhenduanid){
		Zhenduan zhenduan=null;
		session=sessionFactory.openSession();
		String hql="from Zhenduan where zhenduanid=?";
		Query query=session.createQuery(hql);
		query.setInteger(0, zhenduanid);
		List<Zhenduan> list=query.list();
	   
		if (list.size()>0){zhenduan=list.get(0);}
		
	     return zhenduan;
		
		
	}

	public void add(Zhenduan zhenduan){
		session=sessionFactory.openSession();
		Transaction tr=session.beginTransaction();
		
		session.save(zhenduan);
		tr.commit();
		session.close();
		
		
		
	}
	
	public void update(Zhenduan zhenduan){
		session=sessionFactory.openSession();
		Transaction tr=session.beginTransaction();
		
		session.update(zhenduan);
		tr.commit();
		session.close();
		
		
		
	}
	
	public void delete(Zhenduan zhenduan){
		
		Transaction tr=session.beginTransaction();
		
		session.delete(zhenduan);
		tr.commit();
		session.close();
		
		
		
	}
	
	public List<Zhenduan>  scanPart(String date){
		
		session=sessionFactory.openSession();
		String hql="from Zhenduan where date=?";
		Query query=session.createQuery(hql);
		query.setString(0, date);
		List<Zhenduan> list=query.list();
	   
		
		
	     return list;
		
		
	}
	
   


   
   
   public List<Zhenduan>  scanPart(int doctorid){
		
		session=sessionFactory.openSession();
		String hql="from Zhenduan where doctorid=?";
		Query query=session.createQuery(hql);
		query.setInteger(0, doctorid);
		List<Zhenduan> list=query.list();
	   			
	    return list;
		
		
	}
	
   
   public List<Zhenduan>  scanParts(int userid){
		
		session=sessionFactory.openSession();
		String hql="from Zhenduan where userid=?";
		Query query=session.createQuery(hql);
		query.setInteger(0, userid);
		List<Zhenduan> list=query.list();
	   			
	    return list;
		
		
	}
   
   
   public List<Zhenduan>  scanPartss(int departmentid){
		
		session=sessionFactory.openSession();
		String hql="from Zhenduan where departmentid=?";
		Query query=session.createQuery(hql);
		query.setInteger(0, departmentid);
		List<Zhenduan> list=query.list();
	   			
	    return list;
		
		
	}
   
}
